package com.itcodai.utils;

import com.itcodai.entity.User;

import java.io.*;

/**
 * @author c-fanqj
 * @date 2022/8/14
 * @apiNote
 */
public class SerializableTest {

    private static void serialize(User user) throws Exception {
        ObjectOutputStream oos = new ObjectOutputStream(
                new FileOutputStream(new File("D:\\111.txt"))
        );
        oos.writeObject(user);
        oos.close();
    }

    private static User deserialize() throws Exception {
        ObjectInputStream ois = new ObjectInputStream(
          new FileInputStream(new File("D:\\111.txt"))
        );
        return (User) ois.readObject();
    }

    public static void main(String[] args) throws Exception {
        User user = new User();
        /*user.setName("tyshawn");
        user.setAge(18);
        user.setSex("man");*/
        //User.signature = "你眼中的世界就是你自己的样子";
        System.out.println("序列化前的结果：" + user);

        serialize(user);

        //User.signature = "我的眼里只有你";
        User dUser = deserialize();
        System.out.println("反序列化后的结果：" + dUser);

    }

}
